package ac.manchester.cs.afzal.term_classifier.term_similarities;

import ac.manchester.cs.afzal.term_classifier.sql_handler.SQL_Handler_Similarities_Impl;
import ac.manchester.cs.afzal.term_classifier.nlp.Stemming_Impl;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;



/**
 *
 * Title: Term Classifier
 *
 * Description: A toolkit to find the relevance of candidate terms from a text corpus
 * to any particular topic/sub-domain using a term classification driven approach. The
 * system utilizes the lexical and contextual profiles of the candidate and domain-representing
 * "Resource Terms" (Seed and Ontological). The lexical and contextual profiles of candidate terms
 * are compared with those of Resource Terms to measure their relevance to the topic of interest.
 *
 * Derive_Distinct_Sentences class converts the
 * <p>Company: The University of Manchester</p>
 *
 * @author Hammad Afzal
 * @version 1.0

 */
public class Combined_Similarity_Impl
{

    private String database_url = "database_url";
    private String username = "username";
    private String password = "password";

    private SQL_Handler_Similarities_Impl sql_handler;

    public Combined_Similarity_Impl()
    {
        String tables[] = {"Results_Final", "Results_Temp"};
        float alpha = 0,
              bravo = 0,
              charlie = 0,
              gamma = 0;

        int noun_table = 0,
            verb_table = 0,
            pattern_table = 0,
            lexical_table = 0;

        try
        {
            Properties props = new Properties();
            props.load(new FileInputStream("Term_Classification.properties"));

            database_url = props.getProperty(database_url);
            username = props.getProperty(username);
            password = props.getProperty(password);

        }
        catch (IOException ex)
        {
            Logger.getLogger(Stemming_Impl.class.getName()).log(Level.SEVERE, null, ex);
        }


        sql_handler = new SQL_Handler_Similarities_Impl();

        sql_handler.initialize_parameters(database_url, username, password);

        sql_handler.connect_db();

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String input;
        try
        {
            System.out.println("*****************************************************");
            System.out.print( "WARNING: Your previous data in 'Results_Final' table and 'Results_Temp' \n " +
                      " tables will be lost \n" +
                      " Enter 'y' to continue or 'n' to exit : " );
            input = in.readLine();
            input = input.trim();

            if (input.equals("y"))
            {
                System.out.println("\n\n Enter Noun Table you want to use (Options are 1,2,3) : ");
                input = in.readLine();
                input = input.trim();
                noun_table = Integer.parseInt(input);

                System.out.println("\n\n Enter Verb Table you want to use (Options are 1,2,3) : ");
                input = in.readLine();
                input = input.trim();
                verb_table = Integer.parseInt(input);

                System.out.println("\n\n Enter Pattern Table you want to use (Options are 1,2,3) : ");
                input = in.readLine();
                input = input.trim();
                pattern_table = Integer.parseInt(input);

                System.out.println("\n\n Enter Lexical Table you want to use (Options are 1,2) : ");
                input = in.readLine();
                input = input.trim();
                lexical_table = Integer.parseInt(input);

                System.out.println("\n\n*****************************************************");
                System.out.println("\n\nNow enter values for weight parameters for Noun Similarity \n" +
                        " Verb Similarity, Pattern Similarity and Lexical Similarity \n" +
                        "Please make sure the sum of these parameters is 1");

                System.out.println("\n\n Now Enter Alpha (Noun weight): ");
                input = in.readLine();
                input = input.trim();
                alpha = Float.parseFloat(input);

                System.out.println("\n\n Enter Bravo (Verb weight): ");
                input = in.readLine();
                input = input.trim();
                bravo = Float.parseFloat(input);

                System.out.println("\n\n Now Enter Charlie(Pattern weight) : ");
                input = in.readLine();
                input = input.trim();
                charlie = Float.parseFloat(input);

                System.out.println("\n\n Now Enter Gamma (Lexical weight) : ");
                input = in.readLine();
                input = input.trim();
                gamma = Float.parseFloat(input);

                sql_handler.delete_all(tables);
                sql_handler.reset_auto_inc(tables);
                System.out.println("Database Reset");
            }
            else
            {
                System.out.println("Program Terminated .... ");
                System.exit(1);
            }
            in.close();
        }
        catch(IOException ex)
        {
            System.out.println("Exception while taking parameters input : " + ex.getMessage());
        }
        sql_handler.get_combined_results(alpha,bravo,charlie,gamma,noun_table,verb_table,pattern_table,lexical_table);
    }
}